﻿using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace Quickuse.Logging
{
    /// <summary>
    /// LoggerProvider
    /// </summary>
    internal class LoggerProvider : ILoggerProvider
    {
        /// <summary>
        /// LogCallback
        /// </summary>
        protected Action<string, LogLevel> LogCallback { get; set; }

        /// <summary>
        /// Filter
        /// </summary>
        protected Func<string, LogLevel, bool> Filter { get; set; }

        /// <summary>
        /// LoggerProvider
        /// </summary>
        /// <param name="logCallback">logCallback</param>
        /// <param name="filter">filter</param>
        public LoggerProvider(Action<string, LogLevel> logCallback, Func<string, LogLevel, bool> filter = null)
        {
            LogCallback = logCallback;
            Filter = filter;
        }

        /// <summary>
        /// CreateLogger
        /// </summary>
        /// <param name="categoryName">categoryName</param>
        /// <returns></returns>
        public virtual ILogger CreateLogger(string categoryName)
        {
            return new Logger(categoryName, LogCallback, Filter);
        }

        /// <summary>
        /// Dispose
        /// </summary>
        /// <param name="disposing">disposing</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {

            }
        }

        /// <summary>
        /// Dispose
        /// </summary>
        public virtual void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}
